package com.spring.demo8.eg3;

import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;

import java.util.Arrays;

/**
 * @author vhans
 */
public class BeanDefinitionRegistryTest {

    @Test
    public void test1() {
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();

        // 定义一个bean
        GenericBeanDefinition nameBdf = new GenericBeanDefinition();
        nameBdf.setBeanClass(String.class);
        nameBdf.getConstructorArgumentValues().addIndexedArgumentValue(0, "Vhans");

        factory.registerBeanDefinition("name", nameBdf);

        System.out.println("BeanDefinition: " + factory.getBeanDefinition("name"));
        System.out.println("是否注册: " + factory.containsBeanDefinition("name"));
        System.out.println("注册名称列表: " + Arrays.asList(factory.getBeanDefinitionNames()));
        System.out.println("注册的bean数量: " + factory.getBeanDefinitionCount());
        System.out.println("是否使用名称name: " + factory.isBeanNameInUse("name"));

        factory.registerAlias("name", "name_alias1");
        factory.registerAlias("name", "name_alias2");

        System.out.println("别名name_alias1是否使用: " + factory.isAlias("name_alias1"));
        System.out.println("name的别名列表: " + Arrays.asList(factory.getAliases("name")));
    }
}
